package com.jgy.controller;

import com.jgy.config.BusinessException;
import com.jgy.utils.R;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;

import javax.swing.text.html.parser.Entity;

/**
 * @author 姜光远
 * @date 2023/7/25 10:29
 */
@RestController
public class ExcetionController {

    @PostMapping("/save")
    @Transactional(rollbackFor = Exception.class)
    public R save() {
        try {
            String name = null;
            int length = name.length();
        } catch (NullPointerException e) {
          throw new BusinessException(1001,"空指针处理");
        }


        try {
            int i = 6;
            int j = 10;
            int k =  j / i ;
        } catch (ArithmeticException e) {
          throw new BusinessException(1002,"除数不能数为0");
        }

        return R.ok();
    }
}
